package com.qlogic.commons.utils.json.tests;

import com.qlogic.commons.utils.json.JsonArray;
import com.qlogic.commons.utils.json.JsonException;
import com.qlogic.commons.utils.json.JsonObject;

public class ParseJson {
	
	public static void main (String [] args) throws JsonException {
		String tpl = "{toto: 'salut', fofo: {\"go go\": 'qjhj', soso: 5, arr:[{}, {},,'hgh']}}";
		StringBuilder sb = new StringBuilder ();
		sb.append ("[");
		for (int i = 0; i < 10000; i++) {
			sb.append (tpl);
			if (i != 9999) {
				sb.append (", ");
			}
		}
		sb.append ("]");
		String in = sb.toString ();
		sb.setLength (0);
		sb = null;
		long start = System.currentTimeMillis ();
		JsonArray json = new JsonArray (in);
		long end = System.currentTimeMillis ();
		System.out.println ("Read Time  : [" + (end - start) + "] for an in of length: " + in.length ());
		
		JsonObject o = new JsonObject ();
		JsonArray arr = new JsonArray ();
		arr.add (new JsonObject ("{coo: 'hgh', gooo: 45.12}"));
		o.set ("subarr", arr);
		json.add (o);
		String out = json.toString (2);
		System.out.println ("Write Time : [" + (System.currentTimeMillis () - end) + "] for an out of length: " + out.length ());
		System.out.println (out);
	}
	
}
